'use strict';

const account = require('./kujomiva/account.config');
const database = require('./kujomiva/database.config');
const verifyLogin = require('./kujomiva/verifyLogin.config');
/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
    /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
    const config = exports = {};

    // use for cookie sign key, should change to your own and keep security
    config.keys = appInfo.name + '_1561611543740_2908';

    // csrf配置
    config.security = {
        csrf: false
    // csrf: {
    //   useSession: false,
    //   queryName: '_csrf',
    //   bodyName: '_csrf',
    //   headerName: 'x-csrf-token',
    //   ignore: ctx => {
    //     const { method, url } = ctx.request
    //     return url === '/userLogin' && method === 'POST'
    //   }
    // }
    };

    // cors设置
    config.cors = {
        origin: '*'
    };

    // add your middleware config here
    config.middleware = ['verifyLogin', 'verifyAdmin'];
    // 登录验证中间件配置
    config.verifyLogin = verifyLogin;

    // 数据库配置
    config.mysql = {
        // client: {
        //     host: '127.0.0.1',
        //     port: '3306',
        //     user: 'root',
        //     password: 'fami1043829026',
        //     database: 'kujomiva'
        // },
        client: {
            host: '39.104.181.160',
            port: '3307',
            user: 'root',
            password: 'root123456!@AA***',
            database: 'kujomiva'
        },
        // client: { ...account(appInfo).mysql_pro },
        app: true,
        agent: false
    };

    // 文件上传配置
    config.multipart = {
        fileExtensions: ['.flv'],
        fileSize: '1024mb'
    };

    // socket.io 配置
    config.io = {
        init: {},
        namespace: {
            '/': {
                // connectionMiddleware: ['IoMiddlewareConnection'],
                // packetMiddleware: ['IoMiddlewarePacket']
            },
            '/api': {
                connectionMiddleware: ['IoMiddlewareConnection'],
                packetMiddleware: ['IoMiddlewarePacket']
            }
        }
    };

    // add your user config here
    const userConfig = {
    // myAppName: 'egg',
        ...database,
        ...account
    };

    return {
        ...config,
        ...userConfig
    };
};
